{template 'header'}
<link href="./resource/css/app.css" rel="stylesheet">
<ul class="nav nav-tabs">
    <li class=""><a href="{php echo $this->createWeburl('goods');}">商品管理</a></li>
    <li class=""><a href="{php echo $this->createWeburl('goods', array('op' => 'addshow'));}">添加商品</a></li>
    <li class="active"><a href="{php echo $this->createWeburl('integralGoods')}">积分商品管理</a></li>
    <li class=""><a href="{php echo $this->createWeburl('integralGoods', array('op' => 'addshow'));}">添加积分商品</a></li>
</ul>
<div class="panel panel-default">
    <div class="table-responsive panel-body">
        <table class="table table-hover">
            <thead class="navbar-inner">
            <tr>
                <th style="width:80px;">id</th>
                <th style="width:80px;">分类名称</th>
                <th style="width:80px;">商品名</th>
                <th style="width:80px;">图片</th>
                <th style="width:80px;">价格</th>
                <th style="width:70px;">积分</th>
                <th style="width:85px;">签到页</th>
                <th style="width:85px;">库存</th>
                <th style="width:85px;">已兑换</th>
                <th style="width:60px;">是否包邮</th>
                <th style="width:60px;">上下架</th>
                <th style="width:60px;">顺序</th>
                <th style="width:80px;">操作</th>
            </tr>
            </thead>
            <tbody>
            {loop $goods['list'] $k}
            <tr>
                <td>{$k['id']}</td>
                <td>{$k['category']}</td>
                <td>{$k['goods_name']}</td>
                <td><img src="{php echo tomedia($k['cover_image'])}" width="39px" height="39px"></td>
                <td>{$k['original_price']}</td>
                <td>{$k['exchange_number']}</td>
                <td>{php echo $k['is_home'] ==1 ? '不显示' : '显示'}</td>
                <td>{$k['inventory']}</td>
                <td>{$k['exchange_num']}</td>
                <td>{php echo $k['is_free'] ==1 ? '包邮' : '不包邮'}</td>
                <td>{php echo $k['status'] ==1 ? '上架' : '下架'}</td>
                <td><input type="text" value="{$k['sort']}" class="sort" style="width: 30px;" data-id="{$k['id']}"></td>
                <td>
                    <a class="btn btn-success  btn-sm" href="{php echo $this->createWeburl('integralGoods', array('op' => 'editshow', 'id' => $k['id']));}" data-id="{$k['id']}" >编辑</a>
                    <a class="btn btn-info  btn-sm" href="{php echo $this->createWeburl('buy', array('type' =>2,'id' => $k['id']));}" data-id="{$k['id']}" >购买</a>
                    <a href="javascript:;" data-id="{$k['id']}" class="delete btn btn-warning  btn-sm">删除</a>
                </td>
            </tr>
            {/loop}
            </tbody>
        </table>
    </div>
    {$goods['pages']}
</div>
<script type="application/javascript">
    $(function () {
        $('.delete').click(function () {
            if (!confirm('确认要删除该商品')) {
                return false;
            }
            id = $(this).data('id');
            $.post('', {id:id, op:'delete'}, function (data) {
                if (data.status == 1) {
                    location.href = location.href;
                } else {
                    alert('删除失败');
                }

            }, 'json')
        });


        $('.sort').blur(function () {
            var sort = $(this).val();
            var  id = $(this).data('id');
            $.post('', {id:id,sort:sort, op:'sort'}, function (data) {
                if (data.status == 1) {
                    location.href = location.href;
                } else {
                    alert('排序失败');
                }
            }, 'json')
        });
    });

</script>